package com.tro.generator.web;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tro.generator.ftl.FreeMarkerLoad;

import freemarker.core.ParseException;
import freemarker.template.Configuration;
import freemarker.template.MalformedTemplateNameException;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateNotFoundException;
public class Test {
	public static void main(String[] args) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException {
		//指定版本号
        Configuration cfg=new Configuration(Configuration.VERSION_2_3_22);
        //设置模板目录
        cfg.setClassForTemplateLoading(FreeMarkerLoad.class,"");
        //设置默认编码格式
        cfg.setDefaultEncoding("UTF-8");
        Map<String,Object> col=new HashMap<>();
        List<Map<String,Object>> cols=new ArrayList<>();
        for(int i=0;i<3;i++){
        	col=new HashMap<>();
        	col.put("colName", "id"+i);
        	col.put("colComment", "名称"+i);
        	cols.add(col);
        }
        //数据
        Map<String, Object> product = new HashMap<>();
        product.put("table", "");
        product.put("tableName", "leeko_test");
        product.put("cols", cols);
        
        //从设置的目录中获得模板
        Template temp = cfg.getTemplate("test.ftl");
        
        //合并模板和数据模型
        
      //  Writer out = new FileWriter(new File("/Users/apple/Desktop/" + "leeko_test_list1.jsp"));
        Writer out=new OutputStreamWriter(System.out);  
        temp.process(product, out);
        
        //关闭
        out.flush();
        out.close();
	}
}
